<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8">
    <title>物料反查</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content="no-cache, no-store, must-revalidate" http-equiv="Cache-Control"/>
    <meta content="no-cache" http-equiv="Pragma"/>
    <meta content="0" http-equiv="Expires"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <link rel="stylesheet" href="../styles/base.css"/>
     <link rel="stylesheet" href="../styles/common.css"/>
    <link rel="stylesheet" href="../styles/font/iconfont.css"/>
    <link rel="stylesheet" href="../jqueryNicepage/css/layui.css"  media="all">
    <link rel="stylesheet" href="../styles/jquery.multiselect.css"/>
    <style>
        body{
            background:#ddecf5;
            /*overflow-y: scroll;*/
        }
        .seachHeader span{
            margin-top: 5px;
            float: left;
            display: inline-block;
            height:30px;
            line-height: 30px;
            font-size: 16px;

        }
        .seachHeader span:first-child{
            margin-left: 20px;
        }
        .seachHeader span:last-child{
            margin-left: 20px;
        }
        .seachHeader .inputBox{
            float:left;
            width:200px;
            height:37px;
            line-height: 37px;
            font-size: 14px;
            padding-left: 10px;
            position: relative;
            margin-top:-5px;
        }
        .seachHeader .inputBox input{
            width:190px;
            height:37px;
            line-height: 37px;
            position: absolute;
            padding-left: 10px;
            left:0;
        }
        .searchSureBtn{
            margin-left: 330px;
            float:right;
            background-color: #eee;
            font-family: 'Open Sans', sans-serif;
            font-size: 14px;
            text-decoration: none;
            font-weight: 600;
            color: #333;
            position: relative;
            padding: 1px 15px;
            margin-right: 15px;
           /* margin-top:2px;*/
            border-top-right-radius: 10px;
            border-bottom-right-radius: 10px;
            border-top-left-radius: 10px;
            border-bottom-left-radius: 10px;
            background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0, rgb(242,242,242)), color-stop(1, rgb(242,242,242)) );
            cursor: pointer;
            overflow: hidden;
        }
        .searchSureBtn:hover{
            color:#fff;
            background:#40E0D0;
        }
        .searchContainer{
            position:relative;
            width:96%;
            margin-left: 2%;
            margin-top:0px;
            max-height: 98%;
        }
        .formContent{
            height:auto;
           /* overflow-y: scroll;*/
        }
        .formContent center{
            margin-top:-10px;
        }
        .formContent .layui-table tr td:first-child, .formContent .layui-table tr th:first-child{
            max-width:999px ;
            width:30px;
        }
        .formContent center #pageBar2{
            position:absolute;
           /* bottom:10px;*/
            width:100%;
            text-align: center;
            display:none;
        }
        #select_ms{
            top:10px;
            margin-left:50px;
        }
        .ui-multiselect-checkboxes{
            border:1px solid #ccc;
            background:#fff;
        }
        .ui-multiselect-checkboxes li{
            border-bottom:1px solid #ccc;
            height:40px;
            line-height:40px;
            padding-left:5px;
        }
        .ui-multiselect-checkboxes{
            display: none;
        }
    </style>
</head>
<body>
<div id="loading">
    <img src='../styles/img/loading.gif' />
</div>
<div class="searchContainer">
    <div class="seachHeader">
        <span>物料编号：</span>
        <span class="centerInput"></span>
        <span>
            <select id='select' multiple="multiple"></select>
            <div class="searchSureBtn">搜索</div>
        </span>
       <!-- <span></span>-->
    </div>
    <div class="formContent">
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script src="../js/common/publicClass.js"></script>
<script src="../js/common/myAjax.js"></script>
<script src="../js/common/utils.js"></script>
<script src="../layer/layer.js" charset="utf-8"></script>
<script language="Javascript" src="../jqueryNicepage/js/layui.js"></script>
<script type="text/javascript" src="../js/common/jquery-ui.min.js"></script>
<script type="text/javascript" src="../js/common/jquery.multiselect.js"></script>

<script>
    /*var heightform=$(".searchContainer").height()-$(".seachHeader").height()-20;
    $(".formContent").css("height",heightform*0.90);*/
    var textsArr=[];
    maximizeWindow();//设置屏幕大小
    $('#select').multiselect({
        noneSelectedText: "==请选择视图==",
        checkAllText: "",
        uncheckAllText: '',
        selectedText: '# 个被选中',
        click:function(event,ui){
            var oHeight = $("#select_ms").height();
            $("#select_ms").css({
                "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"
            })
            if(ui.checked){
                textsArr.push(ui.text)
            }else{
                var index;
                if(!textsArr.indexOf){
                    textsArr.indexOf = function(elt /*, from*/){
                        var len = this.length >>> 0;
                        var from = Number(arguments[1]) || 0;
                        from = (from < 0)
                            ? Math.ceil(from)
                            : Math.floor(from);
                        if (from < 0)
                            from += len;
                        for (; from < len; from++)
                        {
                            if (from in this &&
                                this[from] === elt)
                                return from;
                        }
                        return -1;
                    };
                    index=textsArr.indexOf(ui.text);
                }else{
                    index= textsArr.indexOf(ui.text);
                }

                if(index>(-1)){
                    textsArr.splice(index, 1);
                }
            }
        },
        selectedList:4
    });
    $(".centerInput").append(setInput("请输入物料编号","",50,"text"));
    $(".publicInputText").focus(function(){
        $("label").css({
            "display":"none"
        })
    })
    $(".publicInputText").blur(function(){
        if($(this).val()!=""){

        }else{
            $("label").css({
                "display":"inline-block"
            })
        }
    })
    function getSelectData(datas){
        $("#select").empty();
        var option=""
        for(var dat=0;dat<datas.length;dat++){
             option += "<option value="+dat+">"+datas[dat].view+"</option>";

        }
        if($("#select option").length==0){
            $("#select").append(option);
            $(".ui-multiselect-checkboxes").css({
                "max-height":"175px"
            })
            $("#select").multiselect('refresh');
        }
    }
    $('.centerInput input').change(function(){
        textsArr=[];
    })
    $('.centerInput input').blur(function(){
        var val = $(".publicInputText").val().replace(/\s+/g,"");
        if(val!=""){
            findView();
        }

    })
    $("#select_ms").click(function(){
        if($("#select option").length==0){
            findView();
        }
        $(".ui-multiselect-checkboxes").css({
            "display":"block"
        })
    })
    $("#select_ms span").click(function(){
        if($("#select option").length==0){
            findView();
        }
        $(".ui-multiselect-checkboxes").css({
            "display":"block"
        })
    })
    $('.centerInput input').bind('keyup', function(event) {
        if (event.keyCode == "13") {
            //回车执行查询
            findView();
        }
    });
    function findView(){
        if($(".publicInputText").val()!=""){
            var url = "/tmEcoSingleSearch",
                data = {
                    datalist: [{"partnumber":encodeURIComponent($(".publicInputText").val().replace(/\s+/g,""))}]
                };
                //data="number="+;
            $("#loading").css({
                display:"block"
            });
            myAjax(url,data,blurSucCallback);
            function blurSucCallback(str){
                textsArr=[];
                $("#loading").css({
                    display:"none"
                });
                if(str.result!=''&&str.result!=undefined){
                    layerFn(str.result);
                }
                if(str.datalist.length>0){
                    dataLists=str.datalist;
                    getSelectData(str.datalist);

                }else{
                    if(str.length==0&&str.datalist.length==0&&str.result==''){
                        layerFn("您查询的数据在非Design视图中不存在");
                    }

                }

            }
            var height=document.body.clientHeight;
            var width =document.body.clientWidth;
            $("#loading img").css({
                "margin-left":width/2-25+"px",
                "margin-top":height/2-25+"px"
            })
        }else{
            layerFn("请输入物料编号！");
        }
    }
    $(".searchSureBtn").click(function(){
        if($(".publicInputText").val()!=""){
            var url = "/MaterialReverse/tmMaterialReverse",
                data="number="+encodeURIComponent($(".publicInputText").val().replace(/\s+/g,""))+"&view="+textsArr;
            $("#loading").css({
                display:"block"
            });
            MaterialReverseAjax(url,data,suCallback);
            var height=document.body.clientHeight;
            var width =document.body.clientWidth;
            $("#loading img").css({
                "margin-left":width/2-25+"px",
                "margin-top":height/2-25+"px"
            })
        }else{
            layerFn("请输入物料编号！");
        }

    })
    function suCallback(str){
        $("#loading").css({
            display:"none"
        });
        if(str.datalist!=undefined&&str.datalist.length>0){
            var dataListObjArr=[];
            for(var i=0;i<str.datalist.length;i++){
                var dataListObj={};
                dataListObj.Number=str.datalist[i].Number!=undefined?str.datalist[i].Number:"";

                dataListObj.State=str.datalist[i].State!=undefined?str.datalist[i].State:"";//物料状态

                dataListObj.PartView=str.datalist[i].PartView!=undefined?str.datalist[i].PartView:"";
                dataListObj.FinishpartNumber=str.datalist[i].FinishpartNumber!=undefined?str.datalist[i].FinishpartNumber:"";
                dataListObj.StateA=str.datalist[i].StateA!=undefined?str.datalist[i].StateA:"";//成品状态

                dataListObj.FinishpartVersion=str.datalist[i].FinishpartVersion!=undefined?str.datalist[i].FinishpartVersion:"";
                dataListObj.FinishpartView=str.datalist[i].FinishpartView!=undefined?str.datalist[i].FinishpartView:"";
                dataListObj.SemiFinishedGoodNumber=str.datalist[i].SemiFinishedGoodNumber!=undefined?str.datalist[i].SemiFinishedGoodNumber:"";
                dataListObj.StateB=str.datalist[i].StateB!=undefined?str.datalist[i].StateB:"";//半成品状态

                dataListObj.SemiFinishedGoodVersion=str.datalist[i].SemiFinishedGoodVersion!=undefined?str.datalist[i].SemiFinishedGoodVersion:"";
                dataListObj.SemiFinishedGoodView=str.datalist[i].SemiFinishedGoodView!=undefined?str.datalist[i].SemiFinishedGoodView:"";
                dataListObjArr.push(dataListObj);
            }
            window.historyList1=dataListObjArr;
            window.headers1=["序号","物料编号","物料状态","物料视图","成品编码","成品状态","成品版本","成品视图","半成品编码","半成品状态","半成品版本","半成品视图"] //table的列名
            window.widths1=["100","200","200","200","200","200","200","200","200","200","200","200"]
            $(".formContent").empty().load('./newTable.html',"",function(){
                setTimeout(function(){
                    var heightform=$(".searchContainer").height()-$(".seachHeader").height()-20;

                    if($(".formContent")[0].offsetHeight>(heightform*0.85)){
                        $("#pageBar2").css("top",heightform*0.85+$(".seachHeader").height()+23)
                    }else{
                        $("#pageBar2").css("top",$(".formContent")[0].offsetHeight+$(".seachHeader").height()+50);
                    }
                    $("#pageBar2").css("display","block")
                    $(".formContent").css({
                        "max-height":heightform*0.85,
                        "overflow-y":"scroll"
                    });
                    clearTimeout();
                },200)
            });
        }else{
            layerFn("您查询的数据不存在！");
            $(".formContent").empty();
        }
    }
    $(".formContent").scroll(function() {
        var scrolltop=$(this).scrollTop();
        if(scrolltop>0){
            $("#table2 table thead").css({
                "position":"absolute",
                "background":"#f2f2f2",
                "opacity":"1",
                "z-index": 999,
                "top":"62px"
            })
        }else{
            $("#table2 table thead").css({
                "position":""

            })
        }
        for (var i = 0; i <  window.headers1.length; i++) {
            var width = $("#table2 table tbody tr:first-child td").eq(i).width();

            if(IEVersion()>(8)){
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width-2
                })

            }if(IEVersion()==(8)){
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width+1
                })
            }else{
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                "width": width+1
            })}
        }
    })
    $(window).resize(function () { //当浏览器大小变化时
        //console.log($("#table2 table").width())
        $("#table2 table thead tr").css({
            "width":$("#table2 table").width()

        })
        var heightform=$(".searchContainer").height()-$(".seachHeader").height()-20;


        $(".formContent").css({
            "max-height":heightform*0.85,
            "overflow-y":"scroll"
        });
        if($(".formContent")[0].offsetHeight>(heightform*0.85)){
            $("#pageBar2").css("top",heightform*0.85+$(".seachHeader").height()+23)
        }else{
            $("#pageBar2").css("top",$(".formContent")[0].offsetHeight+$(".seachHeader").height()+50);
        }
        for (var i = 0; i <  window.headers1.length; i++) {
            var width = $("#table2 table tbody tr:first-child td").eq(i).width();

            if(IEVersion()>(8)){
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width-2
                })

            }if(IEVersion()==(8)){
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width+1
                })
            }else{
                $("#table2 .layui-table thead tr:first-child th").eq(i).css({
                    "width": width+1
                })}
        }
    });
</script>
</html>